package Weapons;

import game.Config.BulletFactory;
/**
 * This class represents a shotgun in the game. The shotgun 
 * extends Weapon, and can fire bullets.
 * When the shotgun fires bullets it spawns multiple bullets spread
 * at a given angle.
 * @author Sebastian Isheden and Victor Beer
 */
import org.newdawn.slick.geom.Vector2f;
public class Shotgun extends Weapon	{

	float numberOfBullets;
	double spread;
	float fadeDistance;
	/**
	 * Creates a shotgun with given parameters. 
	 * @param fireRate	The amount of times this weapon can fire per second.
	 * @param damage  The damage per shot of this weapon.
	 * @param bulletSpeed  The speed the fired bullets will traverse the screen.
	 * @param numBullets The number of bullets the shotgun will spawn when fired.
	 * @param spread The spread of the shotgun.
	 * @param fadeDistance The distance the bullets will be able to travel before disappearing. 
	 */
	public Shotgun(float fireRate, float damage, float bulletSpeed,float numBullets, double spread,float fadeDistance) {
		super(fireRate, damage, bulletSpeed);
		this.numberOfBullets = numBullets;
		this.spread = spread;
		this.fadeDistance = fadeDistance;
	}
	@Override
	protected void spawnBullet(Vector2f position, Vector2f direction) {
		double spreadPerBullet = spread/numberOfBullets;
		double startTheta = -spread/2 + spreadPerBullet/2;	
		for(int i = 0; i < numberOfBullets; i++) {
			Vector2f offsetDirection = direction.copy().add(startTheta + i * spreadPerBullet);
			callFactory(position,offsetDirection);
		}
	}
	/**
	 * Returns a copy of the shotgun.
	 */
	@Override
	public Weapon copy() {
		return new Shotgun(1/this.fireInterval,this.damage,this.bulletSpeed,this.numberOfBullets,this.spread,this.fadeDistance);
	}
	@Override
	protected void callFactory(Vector2f position, Vector2f direction) {
		BulletFactory.createFadingBullet(this.damage,this.bulletSpeed, position, direction,this.fadeDistance);
	}

}
